<template>
  <div class="page">
    <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
          <div class="layui-card">
            <div class="layui-card-body">
              <div class="layui-form" lay-filter>
                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-inline">
                      <input
                        type="text"
                        name="title"
                        v-model="itemData.name"
                        placeholder="请输入标题"
                        autocomplete="off"
                        class="layui-input"
                      />
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">Logo</label>
                    <div class="layui-input-inline" style="width: 180px;">
                      <div class="layui-upload">
                        <button
                          type="button"
                          class="layui-btn"
                          id="layuiadmin-upload-useradmin"
                        >选择文件</button>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">图片预览</label>
                    <div class="layui-input-inline" style="width: 180px;">
                      <img
                        id="img"
                        :src="
                          itemData.logo
                            ? itemData.logo
                            : require('@/assets/zwyl.jpg')
                        "
                        style="width:100px;height:100px;"
                      />
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-input-block">
                    <button
                      class="layui-btn layui-btn-normal"
                      lay-submit
                      lay-filter="setmyinfo"
                      @click="confirmOk"
                    >确认</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "goodsfladd",
  data() {
    return {
      id: "",
      itemData: {
        logo: "",
        news: "",
        title: "",
        targetId: "",
        targetType: "",
      }, //商品回选
    };
  },
  mounted() {
    var _this = this;
    layui.use("upload", function () {
      var upload = layui.upload;
      var uploadInst = upload.render({
        elem: "#layuiadmin-upload-useradmin", //绑定元素
        data: {
          type: 2,
        },
        url: imguploadurl, //上传接口
        done: function (res) {
          layer.msg("上传成功");
          _this.itemData.logo = res.msg;
        },
        error: function () {
          layer.msg("上传失败");
        },
      });
    });
    window.getdates = this.getdates;
  },
  methods: {
    getdates: function (data) {
      var _this = this;
      this.id = data.id;
      var url = "/advert/papi/v1.9/news-target/" + data.id;
      ajaxRequest(url, "GET", "json", "", function (ret, err) {
        _this.itemData = ret.data;
      });
    },
    confirmOk: function () {
      var _this = this;
      var dates = this.itemData;
      dates.id = this.id;
      var url = "/advert/aapi/v1.9/news-target";
      ajaxRequest(url, "PUT", "json", dates, function (ret, err) {
        layer.msg("操作成功");
        setTimeout(function () {
          var index = parent.layer.getFrameIndex(window.name);
          parent.layer.close(index);
          parent.location.reload();
        }, 1000);
      });
    },
  },
  updated: function () {
    var _this = this;
    layui.use("form", function () {
      var form = layui.form;
      form.render();
    });
  },
};
</script>
<style scoped>
</style>
